/**
 * 
 */
package com.desksoft.ecommerce.helper.mall;

import com.desksoft.ecommerce.constants.Constants;
import com.desksoft.ecommerce.service.interf.mall.ISettingService;
import com.desksoft.ecommerce.util.holder.ApplicationContextHolder;
import com.desksoft.ecommerce.util.result.ServiceResult;
import com.desksoft.ecommerce.vo.mall.MallSiteInfoVO;
import com.desksoft.utility.cache.DelegateMemcache;
import com.desksoft.utility.resource.PropertiesUtil;

/***************************************
 * <pre>
 * 版权所有：杭州迪科软件 保留所有权利
 * 创建日期: Jun 25, 2012
 * 创建作者：yejw
 * 文件名称：SiteinfoHelper.java
 * 版本：1.0
 * 功能：
 * 最后修改时间：Jun 25, 2012
 * 修改记录：
 * </pre>
 *****************************************/
public class SiteinfoHelper {
	
	private SiteinfoHelper() {}
	
	private  static  MallSiteInfoVO vo = null ;
	
	
	/**
	 * 得到实例
	 * @return
	 */
	public static synchronized MallSiteInfoVO getInstance(){
		if(vo == null){
			vo = get();
		}
		return vo ;
	}
	

	/**
	 * 取站点信息
	 * 
	 * @param cache
	 * @return
	 */
	private static synchronized MallSiteInfoVO get() {
		DelegateMemcache cache  = 	ApplicationContextHolder.get("memcache");
		MallSiteInfoVO siteInfo = (MallSiteInfoVO) cache.get(Constants.MALL_SITE_INFO_KEY);

		if (null != siteInfo) {
			return siteInfo;
		}

		ISettingService settingService = ApplicationContextHolder.get("settingService");

		// checkNotNull(settingService, "The settingService must not be null!");

		String userId = PropertiesUtil.getProperty("mall.site.userid");
		String storeCode = PropertiesUtil.getProperty("mall.site.storecode");
		String systype = PropertiesUtil.getProperty("mall.site.systype");

		ServiceResult<MallSiteInfoVO> result = settingService.getWebSiteInfo(userId, storeCode, systype);
		if (result.isSuccess()) {
			siteInfo = result.getResult();
		}

		if (null != siteInfo) {
			cache.set(Constants.MALL_SITE_INFO_KEY, siteInfo);
			return siteInfo;
		}
		
		return siteInfo;
	}
}
